#include<math.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<ctype.h>
#include<stdbool.h>
#include <fcntl.h>  //open();

#include <string.h>    // memset(),bzero      
#include <unistd.h>
#include <sys/time.h>  //gettimeofday();
#include <sys/ioctl.h>
#include <termios.h>
#include <iostream>
using namespace std;

#define C_WGS84_a		6378137.0
#define C_WGS84_b		6356752.3142
#define C_DEG2RAD        0.017453292519943295

double f,e;
double Re2t[3][3];

inline  double sqr(double	x)
{
	return (x * x);
} 

void ECEF2Tangent(double *ECFF)
{
	double value[3];
        
        value[0] = Re2t[0][0]*ECFF[0]+Re2t[0][1]*ECFF[1]+Re2t[0][2]*ECFF[2];
        value[1] = Re2t[1][0]*ECFF[0]+Re2t[1][1]*ECFF[1]+Re2t[1][2]*ECFF[2];
        value[2] = Re2t[2][0]*ECFF[0]+Re2t[2][1]*ECFF[1]+Re2t[2][2]*ECFF[2];
        
        ECFF[0] = value[0];
        ECFF[1] = value[1];
        ECFF[2] = value[2];
        //value[0]=(Re2t*ECEF)[0];value[1]=(Re2t*ECEF)[1];value[2]=(Re2t*ECEF)[2];
	return ;
} 

void llh2ECEF( double *llh)
{
	double value[3];
	double	N = C_WGS84_a/sqrt( 1 - e*e*sqr(sin(llh[0])));

	value[0]= (N + llh[2]) * cos(llh[0]) * cos(llh[1]);
        value[1]= (N + llh[2]) * cos(llh[0]) * sin(llh[1]);
	value[2]= (N*(1-e*e) + llh[2]) * sin(llh[0]);
        llh[0] = value[0];
        llh[1] = value[1];
        llh[2] = value[2];
	return ;
}

int main()
{
	int i,j;
	double llh1[3],llh2[3],pos1[3],pos2[3];
	double err[3],N;
	double distance;
	
	//double zero_position_ECEF[3]

	f = ((C_WGS84_a - C_WGS84_b) / C_WGS84_a);
	e = sqrt( 2*f - f*f );


	


	llh1[0] = (23.0+25.1521478/60.0)*C_DEG2RAD;
	llh1[1] = (112.0+53.6396314/60.0)*C_DEG2RAD;
	llh1[2] = 10.097-9.2;



	//llh2[0] = (23.0+34.7005683/60.0)*C_DEG2RAD;
	//llh2[1] = (113.0+7.5611949/60.0)*C_DEG2RAD;
	//llh2[2] = 87.814-8.7;

//	llh2[0] = (23.0+25.1557231/60.0)*C_DEG2RAD;  //minghui
//	llh2[1] = (112.0+53.6389087/60.0)*C_DEG2RAD;
//	llh2[2] = 7.484-9.2;

	//llh2[0] = (21.0+25.7391744/60.0)*C_DEG2RAD;  //feihaidaojiguang
	//llh2[1] = (110.0+59.4239254/60.0)*C_DEG2RAD;
	//llh2[2] = 9.892-12.20;

	llh2[0] = (23.0+9.3965209/60.0)*C_DEG2RAD;  //feihaidaotuxiang
	llh2[1] = (113.0+20.4864398/60.0)*C_DEG2RAD;
	llh2[2] = 45.624-6.80;



	//llh2[0] = (23.0+25.1521686/60.0)*C_DEG2RAD;
	//llh2[1] = (112.0+53.6373325/60.0)*C_DEG2RAD;
	//llh2[2] = 10.185-9.2;

	double		clat = cos(llh2[0]);
        double		clon = cos(llh2[1]);
        double		slat = sin(llh2[0]);
        double		slon = sin(llh2[1]);

	Re2t[0][0] = -slat*clon;
	Re2t[0][1] = -slat*slon;
	Re2t[0][2] =  clat;

	Re2t[1][0] = -slon;
	Re2t[1][1] =  clon;
	Re2t[1][2] =  0.0;

	Re2t[2][0] = -clat*clon;
	Re2t[2][1] = -clat*slon;
	Re2t[2][2] = -slat;

	llh2ECEF(llh1);
	llh2ECEF(llh2);

	//ECEF2Tangent(llh1);
	//ECEF2Tangent(llh2);

	for(i=0;i<3;i++)
	{
		pos1[i] = llh1[i];
		pos2[i] = llh2[i];	
		err[i] = pos1[i]-pos2[i];
	}
	distance = sqrt((pos1[0]-pos2[0])*(pos1[0]-pos2[0])+(pos1[1]-pos2[1])*(pos1[1]-pos2[1])+(pos1[2]-pos2[2])*(pos1[2]-pos2[2]));
	//printf("%lf %lf %lf \n",pos1[0],pos1[1],pos1[2]);
	printf("%lf %lf %lf \n",llh2[0],llh2[1],llh2[2]);
	//printf("%lf %lf %lf \n",err[0],err[1],err[2]);
	//printf("%lf %lf %lf \n",llh1[0],llh1[1],llh1[2]);

	//printf("%lf \n",distance);
	return 0;	


}













